<template>
  <view class="index">
    <view class="jtop">
      <view class="status_bar"><!-- 这里是状态栏 --></view>
      <view class="jtop_l" @tap="navigateBack"
        ><image src="../../static/img/ic_back.png"></image
      ></view>
      <view class="jtop_c">{{ projectName }}</view>
      <!-- <view class="jtop_r" @click="jshow_pop"><image src="../../static/img/index/new/ic_filter.png"></image></view> -->
    </view>
    <view class="tophr"></view>

    <view class="ml">
      <view
        class="mlb"
        @tap="to_listtwo(index, item.id)"
        v-for="(item, index) in items"
        :key="index"
      >
        <view class="mlbt">{{ item.crtTimeText }}</view>
        <view class="m2_l">
          <image
            src="../../static/img/ic_company.png"
            v-if="item.type == 0"
          ></image>
          <image
            src="../../static/img/ic_Project message.png"
            v-if="item.type == 1"
          ></image>
          <image
            src="../../static/img/ic_System message.png"
            v-if="item.type == 2"
          ></image>
        </view>
        <view class="m2_r">
          <view class="m2_rt">
            {{ item.projectName }}
          </view>
          <view class="m2_rm">
            <text class="m2_rm01">{{ item.title }}</text>
            <text class="m2_rm02">{{ item.content }}</text>
            <text class="m2_rm03">查看详情 ></text>
          </view>
        </view>
      </view>

      <!-- 			
			<view class="mlb">
				<view class="mlbt">7月10日 16:27</view>
				<view class="m2_l"  style="background: #FC9422;">
					<image src="../../static/img/location-fill.png"></image>
				</view>
				<view class="m2_r">
					<view class="m2_rt">
						考勤打卡
					</view>
					<view class="m2_rm">
						<text class="m2_rm01">考勤打卡</text>
						<text class="m2_rm02">还有10分钟就上班了，快来打卡吧！…</text>
						<text class="m2_rm03">立即打卡 ></text>
					</view>
				</view>
			</view>
			
			<view class="mlb">
				<view class="mlbt">7月10日 16:27</view>
				<view class="m2_l"  style="background: #539CF8;">
					<image src="../../static/img/detail-fill.png"></image>
				</view>
				<view class="m2_r">
					<view class="m2_rt">
						工作计划
					</view>
					<view class="m2_rm">
						<text class="m2_rm01">工作计划</text>
						<text class="m2_rm02">这里显示消息详情内容这里显示消息详情内容这里显示消息详情内容…</text>
						<text class="m2_rm03">查看详情 ></text>
					</view>
				</view>
			</view>
			
			<view class="mlb">
				<view class="mlbt">7月10日 16:27</view>
				<view class="m2_l"  style="background: #F7B61B;">
					<image src="../../static/img/carry out-fill.png"></image>
				</view>
				<view class="m2_r">
					<view class="m2_rt">
						施工日志
					</view>
					<view class="m2_rm">
						<text class="m2_rm01">施工日志</text>
						<text class="m2_rm02">这里显示消息详情内容这里显示消息详情内容这里显示消息详情内容…</text>
						<text class="m2_rm03">查看详情 ></text>
					</view>
				</view>
			</view>
			
		
			 -->
    </view>

    <!-- 弹出层 -->
    <view :class="[ashowpop ? 'tc' : 'tc hide']">
      <view class="jtop_bj" @click="jshow_pop"></view>

      <view class="tcl">
        <view class="tcl_t">
          消息筛选
        </view>
        <view class="tcl_t2">
          日期
        </view>

        <view class="tcl_b">
          <view
            :class="true == item.actived ? 'active' : ''"
            @click="labelBtn(index)"
            v-for="(item, index) in aitems"
            :key="item.id"
            >{{ item.name }}</view
          >
        </view>
      </view>
    </view>
  </view>
</template>

<script>
import request from '@/common/request.js';
import { mapState } from 'vuex';

export default {
  data() {
    return {
      repeat_click: true,
      ashowpop: false,
      ashowpop_jrename: false,
      ashowpop_jdel: false,
      ashowpopT: false,
      bj: false,
      yd: false,
      biao: '全部',
      aitems: [
        { name: '全部', actived: true },
        { name: '本月', actived: false },
        { name: '3个月', actived: false },
        { name: '1年', actived: false },
        { name: '2年', actived: false },
      ],

      nodata: true,
      items: [],
      name: '',
      jtitle: '',
      nian: '',
      yue: '',
      re: '',
      week: '',
      today: '',
      projectName: '',
      id: '',
    };
  },

  onShow() {
    var date = new Date();
    var Y = date.getFullYear();
    var M =
      date.getMonth() + 1 < 10
        ? '0' + (date.getMonth() + 1)
        : date.getMonth() + 1;
    var D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
    var h = date.getDate();

    var now = new Date();
    var day = now.getDay();
    var weeks = new Array(
      '星期日',
      '星期一',
      '星期二',
      '星期三',
      '星期四',
      '星期五',
      '星期六',
    );
    var week = weeks[day];

    this.nian = Y;
    this.week = week;
    this.re = D;
    this.yue = M;

    this.today = Y + '-' + M + '-' + D;

    this.id = uni.getStorageSync('temp_data1').groupId;

    if (uni.getStorageSync('temp_data1').name) {
      this.projectName = uni.getStorageSync('temp_data1').name;
    }

    if (uni.getStorageSync('temp_data1').name) {
      this.projectName = uni.getStorageSync('temp_data1').name;
    } else {
      this.projectName = uni.getStorageSync('temp_data1').name;
    }

    // this.data_add("2020-01-01"+" 00:00",this.today+" 24:00");
    this.data_add();
  },

  methods: {
    labelBtn(index) {
      console.log(index);
      for (let i in this.aitems) {
        this.aitems[i].actived = false;
      }

      this.aitems[index].actived = true;

      var jtitle = this.aitems[index];

      this.biao = this.aitems[index].name;

      console.log(index);
      if (index == 0) {
        this.data_add('2020-01-01' + ' 00:00', this.today + ' 24:00');
      }
      if (index == 1) {
        this.data_add(
          this.nian + '-' + this.yue + '-01' + ' 00:00',
          this.today + ' 24:00',
        );
      }

      if (index == 2) {
        var sy2 = this.yue - 3;
        var sy1 = this.nian;
        if (sy2 < 0) {
          sy1 = sy1 - 1;
          sy2 = 12 - Math.abs(sy2);
        }
        if (sy2 == 0) {
          sy2 = '01';
        }
        this.data_add(
          sy1 + '-' + sy2 + '-' + this.re + ' 00:00',
          this.today + ' 24:00',
        );
      }

      if (index == 3) {
        this.data_add(
          this.nian - 1 + '-' + this.yue + '-' + this.re + ' 00:00',
          this.today + ' 24:00',
        );
      }
      if (index == 4) {
        this.data_add(
          this.nian - 3 + '-' + this.yue + '-' + this.re + ' 00:00',
          this.today + ' 24:00',
        );
      }
    },

    data_add(a, b) {
      // this.projectId = uni.getStorageSync('dqfull_name').id;

      // GET /v1/msg/{corpId}/list
      request({
        url: `/msg/group-msg/page/${this.id}`,
        method: 'GET',
        data: {
          size: 100,
          page: 1,
          // type: uni.getStorageSync('temp_data1').type,
          // startTime:a,
          // endTime:b,
        },

        success: res => {
          console.log('2项目列表信息', res);
          console.log(res.data.data);

          if (res.data.success == true) {
            if (res.data.data.rows) {
              this.items = res.data.data.rows;
              console.log(this.items);
              this.nodata = true;

              var jdd = {};
              if (uni.getStorageSync('temp_data1').type == 1) {
                jdd.projectId = uni.getStorageSync('temp_data1').projectId;
                request({
                  url: `/msg/v1/msg/${
                    uni.getStorageSync('user').corpBaseInfoResponse.id
                  }/read/project`,
                  method: 'POST',
                  data: jdd,

                  success: res => {
                    console.log('标记已读', res);

                    request({
                      url: `/msg/group-msg/unread-cnt`,
                      method: 'GET',

                      success: res => {
                        console.log('底部未读消息', res);
                        if (res.data.success == true && res.data.data > 0) {
                          uni.setTabBarBadge({
                            index: 1,
                            text: `${res.data.data}`,
                          });
                        }
                      },
                    });
                  },
                });
              }

              if (uni.getStorageSync('temp_data1').type == 0) {
                jdd.type = 0;
                request({
                  url: `/msg/v1/msg/${
                    uni.getStorageSync('user').corpBaseInfoResponse.id
                  }/read/type`,
                  method: 'POST',
                  data: jdd,

                  success: res => {
                    console.log('标记已读', res);

                    request({
                      url: `/msg/group-msg/unread-cnt`,
                      method: 'GET',

                      success: res => {
                        console.log('底部未读消息', res);
                        if (res.data.success == true && res.data.data > 0) {
                          uni.setTabBarBadge({
                            index: 1,
                            text: `${res.data.data}`,
                          });
                        }
                      },
                    });
                  },
                });
              }
            } else {
              this.items = '';
              this.nodata = false;
            }
          } else {
            this.repeat_click = true;
            uni.showToast({
              title: res.data.msg,
              icon: 'none',
            });
          }
        },
        fail: () => {
          this.repeat_click = true;
          uni.showToast({
            title: '服务器开小差，请稍后~',
            icon: 'none',
          });
          return false;
        },
      });
    },

    // 跳转
    to_listtwo(a) {
      uni.setStorageSync('temp_data2', this.items[a]);
      console.log('aaaaa', this.items[a]);

      uni.navigateTo({
        url: '../msg/msg_more',
      });
    },

    add() {
      uni.navigateTo({
        url: '../main/fi_indate_add',
      });
    },
    to_rl() {
      uni.navigateTo({
        url: '../main/close',
      });
    },
    to_list01() {
      uni.navigateTo({
        url: '../main/fi_indate_more',
      });
    },
    to_list02() {
      uni.navigateTo({
        url: '../main/mate_listtwo',
      });
    },
    to_list03() {
      uni.navigateTo({
        url: '../main/mate_listthree',
      });
    },

    // 跳转
    jshow_pop() {
      this.ashowpop = !this.ashowpop;
    },

    navigateBack() {
      uni.navigateBack();
    },
  },
  computed: mapState(['forcedLogin', 'hasLogin', 'userName']),
};
</script>

<style>
.m2_l {
  width: 80rpx;
  height: 80rpx;
  display: block;
  float: left;
  border-radius: 12rpx;
}
.m2_l image {
  width: 80rpx;
  height: 80rpx;
  display: block;
  float: left;
  margin: 0;
}
.m2_r {
  width: 622rpx;
  height: auto;
  display: block;
  float: left;
}
.m2_rt {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  margin: 0rpx 0 0rpx 32rpx;
  font-size: 24rpx;
  color: #737373;
}
.m2_rm {
  width: 500rpx;
  height: auto;
  display: block;
  float: left;
  margin: 10rpx 0 0rpx 32rpx;
  background: #ffffff;
  border-radius: 8rpx;
  font-size: 24rpx;
  color: #737373;
}
.m2_rm01 {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  font-size: 32rpx;
  color: #000;
  box-sizing: border-box;
  padding: 20rpx 24rpx 15rpx;
}
.m2_rm02 {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  font-size: 28rpx;
  line-height: 36rpx;
  color: #999999;
  box-sizing: border-box;
  padding: 0rpx 24rpx 17rpx;
}
.m2_rm03 {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  font-size: 24rpx;
  line-height: 36rpx;
  color: #59698c;
  box-sizing: border-box;
  padding: 0rpx 24rpx 20rpx;
}

.ml {
  width: 100%;
  height: auto;
  display: block;
  float: left;
}
.mlb {
  width: 702rpx;
  height: auto;
  display: block;
  float: left;
  margin: 40rpx 24rpx 0;
}
.mlbt {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  margin: 0rpx 0 20rpx 0;
  text-align: center;
  font-size: 24rpx;
  color: #999999;
}
.mlbc {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  background: #ffffff;
  border-radius: 8rpx;
}
.mlbct {
  width: 630rpx;
  height: auto;
  display: block;
  float: left;
  font-size: 32rpx;
  line-height: 40rpx;
  color: #000000;
  margin: 24rpx;
}
.mlbcf {
  width: 630rpx;
  height: auto;
  display: block;
  float: left;
  font-size: 32rpx;
  line-height: 40rpx;
  color: #256aff;
  margin: 0 24rpx 24rpx;
}

.mlbimg {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  background: #ffffff;
  border-radius: 8rpx;
  overflow: hidden;
}
.mlbimgt {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  border-radius: 8rpx 8rpx 0 0;
}
.mlbimgf {
  width: 630rpx;
  height: auto;
  display: block;
  float: left;
  font-size: 32rpx;
  line-height: 40rpx;
  color: #000000;
  margin: 30rpx 24rpx;
}

.tcl {
  width: 640rpx;
  height: 100%;
  position: fixed;
  top: 0;
  right: 0;
  z-index: 10001;
  display: block;
  background: #ffffff;
}
.tcl_t {
  width: 100%;
  height: 120rpx;
  line-height: 120rpx;
  display: block;
  float: left;
  text-align: center;
  font-size: 32rpx;
  color: #333333;
  box-sizing: border-box;
  border-bottom: 1px solid #dddddd;
}
.tcl_t2 {
  width: 100%;
  height: auto;
  line-height: 36rpx;
  display: block;
  float: left;
  text-align: left;
  font-size: 28rpx;
  color: #666666;
  box-sizing: border-box;
  padding: 20rpx 30rpx;
}
.tcl_b {
  width: 610rpx;
  display: block;
  float: right;
  font-size: 28rpx;
  color: #333333;
  box-sizing: border-box;
  padding: 0;
  border-bottom: 1px solid #dddddd;
}
.tcl_b view {
  width: 120rpx;
  height: 64rpx;
  display: block;
  float: left;
  text-align: center;
  font-size: 28rpx;
  color: #333333;
  background: #ffffff;
  border: 1px solid #dddddd;
  box-sizing: border-box;
  border-radius: 8rpx;
  line-height: 60rpx;
  margin: 0 20rpx 20rpx 0;
}

.tcl_b view.active {
  color: #1769ff;
  border-color: #1769ff;
}

.zbt {
  width: 100%;
  height: 72rpx;
  line-height: 72rpx;
  display: block;
  float: left;
  text-align: left;
  font-size: 28rpx;
  color: #666666;
  box-sizing: border-box;
  padding-left: 30rpx;
}

.bl {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  background: #ffffff;
  border: 0px solid #dddddd;
  border-left: 0;
  border-right: 0;
  margin: 0rpx 0 0;
}
.blb {
  width: 720rpx;
  margin: 0 0 0rpx 30rpx;
  height: auto;
  display: block;
  float: left;
  border-bottom: 1px solid #dddddd;
}
/* .bl .blb:last-child{border: 0;} */
.blb_l {
  width: 400rpx;
  margin: 18rpx 0 0rpx 0rpx;
  height: auto;
  display: block;
  float: left;
}
.blb_r {
  width: 250rpx;
  height: 25rpx;
  display: block;
  float: right;
  text-align: right;
  margin: 43rpx 30rpx 0 0rpx;
  font-size: 34rpx;
  font-weight: 500;
  color: #000000;
}
.blb_lt {
  width: 100%;
  height: auto;
  line-height: 42rpx;
  display: block;
  float: left;
  font-size: 34rpx;
  color: #000000;
}
.blb_lt text {
  width: auto;
  height: auto;
  line-height: 42rpx;
  display: block;
  float: right;
  font-size: 34rpx;
  color: #000000;
}
.blb_lf {
  width: 100%;
  height: auto;
  line-height: 32rpx;
  display: block;
  float: left;
  font-size: 24rpx;
  color: #999999;
  margin: 10rpx 0 18rpx;
}

.tc {
  width: 100%;
  height: 100%;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 10000;
  display: block;
}
.jtop_bj {
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  position: fixed;
  top: 0;
  left: 0;
  z-index: 10000;
}
.tc_fbox_bt {
  width: 100%;
  height: 90rpx;
  line-height: 90rpx;
  display: block;
  float: left;
  text-align: center;
  font-size: 36rpx;
  color: #000000;
  border-top: 20rpx solid #f2f2f2;
  background: #ffffff;
}
.tc_fbox {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  background: #f2f2f2;
  position: fixed;
  left: 0;
  bottom: 0;
  z-index: 10001;
}
.tc_fbox_bt2 {
  width: 100%;
  height: 90rpx;
  line-height: 90rpx;
  display: block;
  float: left;
  text-align: center;
  font-size: 36rpx;
  color: #000000;
  border-top: 0rpx solid #f2f2f2;
  background: #ffffff;
}
.tc_fbox_bt3 {
  width: 100%;
  height: 90rpx;
  line-height: 90rpx;
  display: block;
  float: left;
  text-align: center;
  font-size: 36rpx;
  color: #000000;
  border-bottom: 1px solid #dddddd;
  background: #ffffff;
}

.tophr {
  width: 100%;
  height: 88rpx;
}
.uni-searchbar {
  box-shadow: none;
}

.index {
  background: #f2f2f2;
  width: 100%;
  height: auto;
}
.jtop {
  width: 100%;
  height: 88rpx;
  background: #ffffff;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1000;
}
.jtop_l {
  width: auto;
  height: 88rpx;
  display: block;
  float: left;
  font-size: 32rpx;
  color: #000000;
  line-height: 88rpx;
  margin: 0 0 0 30rpx;
}
.jtop_l image {
  width: 48rpx;
  height: 48rpx;
  display: block;
  float: left;
  margin: 20rpx 0 20rpx 0;
}
.jtop_lt {
  margin: 0 0 0 10rpx;
}
.jtop_r {
  width: 48rpx;
  height: 48rpx;
  display: block;
  float: right;
  margin: 20rpx 20rpx 0 0;
}
.jtop_rl {
  margin: 20rpx 30rpx 0 0;
}
.jtop_r image {
  width: 48rpx;
  height: 48rpx;
  display: block;
  float: left;
}
.jtop_c {
  width: 70%;
  height: 48rpx;
  line-height: 48rpx;
  display: block;
  float: left;
  position: fixed;
  top: 20rpx;
  left: 15%;
  text-align: center;
  font-size: 36rpx;
  color: #000000;
}
.jtop_c image {
  width: 36rpx;
  height: 36rpx;
  display: inline-block;
  float: none;
  margin-bottom: -5rpx;
  margin-left: 5rpx;
}
.jtop_b {
  width: 100%;
  height: auto;
  background: #ffffff;
  position: fixed;
  top: 88rpx;
  left: 0;
  z-index: 1001;
}

.doc_b22 {
  opacity: 0.5;
}

.nd {
  width: 735rpx;
  height: auto;
  display: block;
  float: left;
  margin: 0 0 0 0rpx;
}
.nd_bt {
  width: auto;
  height: 48rpx;
  display: block;
  float: right;
  border: 1px solid #dddddd;
  border-radius: 24rpx;
  margin: 40rpx 0 40rpx 30rpx;
}
.nd_bt text {
  width: auto;
  height: 48rpx;
  display: block;
  float: left;
  margin: 0 7rpx 0 18rpx;
  line-height: 48rpx;
  color: #666666;
  font-size: 24rpx;
}
.nd_bt image {
  width: 13rpx;
  height: 8rpx;
  display: block;
  float: left;
  margin: 21rpx 14rpx 0 0;
}
</style>
